package com.yotoodesign.dianba.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yotoodesign.core.util.LoadImageAsynTask;
import com.yotoodesign.dianba.R;
import com.yotoodesign.dianba.bean.BaseData;
import com.yotoodesign.dianba.bean.Singer;
import com.yotoodesign.dianba.util.Constant;

public class TopSingerAdapter extends BaseAdapter {

	private Context     mContext;
	private ArrayList<BaseData> singerList;
	
	

	public ArrayList<BaseData> getSingerList() {
		return singerList;
	}

	public void setSingerList(ArrayList<BaseData> singerList) {
		this.singerList = singerList;
	}

	public TopSingerAdapter(Context c){
		this.mContext = c;
	}
	
	@Override
	public int getCount() {
		return singerList!=null?singerList.size():0;
	}

	@Override
	public Object getItem(int position) {
		return singerList!=null?singerList.get(position):null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		View view = LayoutInflater.from(mContext).inflate(R.layout.top_singer_render, null);
		Singer singer = (Singer)singerList.get(position);
		ImageView ivSinger = (ImageView)view.findViewById(R.id.ivSinger);
		LoadImageAsynTask.loadFromUrl(ivSinger, singer.getImageUrl(), Constant.APP_DIR+"/"+Constant.IMAGE_CACHE);
		
		TextView tvSinger = (TextView)view.findViewById(R.id.tvSinger);
		
		tvSinger.setText(singer.getName());
		
		return view;
	}
	

}
